package com.gemptc.service.iphone;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import com.gemptc.bean.Sciencebean;
import com.gemptc.daoimp.RegradImp;
import com.gemptc.daoimp.SelectScienceImp;

/**
 * Servlet implementation class RegradService
 */
@WebServlet("/RegradService")
public class RegradService extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public RegradService() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		int c;
		PrintWriter printWriter = response.getWriter();
		System.out.println("信息");
		String Value = request.getParameter("key");
		switch (Integer.parseInt(Value)) {
		case 1:
			//查看是否关注
			System.out.println("shifouguanzhu");
			int user_id1 = Integer.parseInt(request.getParameter("user_id"));
			int focused_id1 = Integer.parseInt(request
					.getParameter("focused_id"));
			c = Integer.parseInt(request.getParameter("choice"));
			RegradImp regradImp = new RegradImp();
			boolean flag = regradImp.Collect(user_id1, focused_id1, c);
			System.out.println("flag-------" + flag);
			if (flag) {
				System.out.println("收藏");
				printWriter.write("已关注");
			} else {
				System.out.println("weishoucang");
				printWriter.write("没有关注");
			}
			printWriter.close();
			break;
		case 2:
			//添加关注
			System.out.println("加关注");
			int user_id2 = Integer.parseInt(request.getParameter("user_id"));
			int focused_id2 = Integer.parseInt(request
					.getParameter("focused_id"));
			c = Integer.parseInt(request.getParameter("choice"));
			RegradImp regradImp1 = new RegradImp();
			boolean flag1 = regradImp1.Collect(user_id2, focused_id2, c);
			System.out.println(flag1);
			if (flag1) {
				printWriter.write("关注成功");
			} else {
				printWriter.write("关注失败");
			}
			printWriter.close();
			break;
		case 3:
			//取消关注
			System.out.println("取消关注");
			int user_id3 = Integer.parseInt(request.getParameter("user_id"));
			int focused_id3 = Integer.parseInt(request
					.getParameter("focused_id"));
			c = Integer.parseInt(request.getParameter("choice"));
			RegradImp regradImp2 = new RegradImp();
			boolean flag2 = regradImp2.Collect(user_id3, focused_id3, c);
			System.out.println(flag2);
			if (flag2) {
				printWriter.write("已取消关注");
			} else {
				printWriter.write("取消关注失败");
			}
			printWriter.close();
			break;
		default:
			break;

		}
	}

}
